var /**
	 * 仿真流程管理
	 */
TeachFlow = cc.Class.extend({
	step:0,
	flow:null,
	main:null,
	over_flag: false,
	curSprite:null,
	ctor: function(){
		this.init();
	},
	setMain:function(main){
		this.main=main;
	},
	init: function(){
		for(var i in teach_flow){
			teach_flow[i].finish = false;
			teach_flow[i].cur = false;
			if(teach_flow[i].action == null){
				teach_flow[i].action = ACTION_NONE;
			}
		}
	},
	
	start:/**
			 * 开始流程
			 */
	function(){
		this.over_flag = false;
		this.step = 0;
		
		/* 新标准，开始的时候，执行下一步 */
		this.next();
	},
	over:/**
			 * 流程结束，计算分数，跳转到结束场景，
			 */
	function(){
		this.over_flag = true;
		this.flow = over;
		gg.lastStep = this.step;
		this.main.over();
	},
	checkTag:/**
				 * 检查是否当前步骤
				 * 
				 * @deprecated 使用新Angel类，不再判断是否当前步骤
				 * @param tag
				 * @returns {Boolean}
				 */
	function(tag){
		var cur_flow = teach_flow[this.step - 1];
		if(cur_flow.tag == tag){
			return true;
		} else {
			return false;
		}
	},
	prev:/**
			 * 回退一定步数
			 * 
			 * @deprecated 需结合具体实现，，暂时不再启动
			 * @param count
			 *            步数
			 */
	function(count){
		if(this.curSprite!=null){
			this.curSprite = null;
		}
		if(this.flow!=null){
			this.flow.cur = false;
		}
		this.step = this.step - count;
		this.flow = teach_flow[this.step - 1];
		this.refresh();
		gg.score -= 11;
	},
	next:/**
			 * 执行下一步操作， 定位当前任务
			 */
	function(){
		if(this.over_flag){
			return;
		}
		if(this.curSprite!=null){
			this.curSprite.setEnable(false)
			this.curSprite = null;
		}
		if(this.flow!=null){
			this.flow.cur = false;
			// 标记任务已完成
			this.flow.finish = true;
		}
		this.flow = teach_flow[this.step++];
		if(this.flow.finish){
			// 如果任务已完成，跳过当前步骤
			this.next();
		}
		this.refresh();
	},
	refresh:/**
			 * 刷新当前任务状态，设置闪现，点击等状态
			 */
	function(){
		// 刷新提示
		this.flow.cur = true;
		if(this.flow.tip != null){
			ll.tip.tip.doTip(this.flow.tip);
		}
		if(this.flow.flash != null){
			ll.tip.flash.doFlash(this.flow.flash);
		}
		if(this.step > teach_flow.length - 1){
			this.over();
		}
		this.initCurSprite();
		if(this.curSprite!=null){
			this.location();
			this.curSprite.setEnable(true);
		}
	},
	location:/**
	 * 定位箭头
	 */
		function(){
		var tag = gg.flow.flow.tag;
		if(tag instanceof Array){
			if(TAG_LIB_MIN < tag[1]){
				if(ll.run.lib.isOpen()){
					ll.tip.arr.pos(this.curSprite,gg.flow.flow.X,gg.flow.flow.Y);
				}else{
					ll.tip.arr.pos(ll.tool.getChildByTag(TAG_BUTTON_LIB));
				}
			}else{
				ll.tip.arr.pos(this.curSprite,gg.flow.flow.X,gg.flow.flow.Y);
			}
		}
		else {
			ll.tip.arr.pos(this.curSprite,gg.flow.flow.X,gg.flow.flow.Y);
		}		
	},
	getStep:/**
			 * 获取当前步数
			 * 
			 * @returns {Number}
			 */
	function(){
		return this.step;
	},
	initCurSprite:/**
					 * 遍历获取当前任务的操作对象
					 */
	function(){
		var tag = this.flow.tag;
		if(tag == null || tag == undefined){
			return;
		}
		var root = ll.run;
		var sprite = null;
		if(tag == TAG_BUTTON_LIB){
			sprite = ll.tool.getChildByTag(tag);
		} else if(tag instanceof Array){
			// 数组
			for (var i in tag) {
				root = root.getChildByTag(tag[i]);
			}
			sprite = root;
		} else {
			// 单个tag
			var sprite = root.getChildByTag(tag);
		}
		if(sprite != null){
			this.curSprite = sprite;
			return;
		}
	}
});
// 任务流
teach_flow = [
// 取5g粗食盐
	{tip:"1.打开物品库",tag:TAG_BUTTON_LIB},
	{tip:"取出溶解氧仪",tag:[TAG_LIB,TAG_LIB_INSTRUMENT]},
	{tip:"点击溶解氧仪来到溶解氧仪操作界面",tag:TAG_INSTRUMENT},
	{tip:"将溶解氧仪翻转到背面",tag:[TAG_MP_INSTRUMENT,TAG_MAIN,TAG_INSTRUMENT1],X:0.45,Y:1},
	{tip:"打开背面的电源室",tag:[TAG_MP_INSTRUMENT,TAG_MAIN,TAG_INSTRUMENT1],action:ACTION_DO1,X:0.25,Y:0.8},
	{tip:"从物品库中取出电源,将电源嵌入到电源室中",tag:[TAG_LIB,TAG_LIB_BATTERY]},
	{tip:"关闭电源室,将溶解氧仪翻转回正面",tag:[TAG_MP_INSTRUMENT,TAG_MAIN,TAG_INSTRUMENT1],action:ACTION_DO2,X:0.6,Y:0.7},
	{tip:"取出溶解氧电极",tag:[TAG_LIB,TAG_LIB_ELECTRODE]},
	{tip:"旋转保护套将其从电极上取下",tag:[TAG_ELECTRODE_ALL,TAG_ELECTRODE],action:ACTION_DO1,X:0.85,Y:0.15},
	{tip:"逆时针旋转紧帽将其从电极上取下",tag:[TAG_ELECTRODE_ALL,TAG_ELECTRODE],action:ACTION_DO2,X:0.6,Y:0.83},
	{tip:"从紧帽中取出压环(内含衫环及托座)",tag:[TAG_ELECTRODE_ALL,TAG_TIGHT],action:ACTION_DO1},
	{tip:"用工具插入托座底部槽内将托座底部打开",tag:[TAG_ELECTRODE_ALL,TAG_PRESSURE],action:ACTION_DO1},
	{tip:"从托座上取出衫环",tag:[TAG_ELECTRODE_ALL,TAG_BRACKET],action:ACTION_DO1},
	{tip:"从物品库中取出一张新的薄膜,平放在托座上",tag:[TAG_LIB,TAG_LIB_FILM]},
	{tip:"将衫环套在托座上,使薄膜固定,并且平整,紧绷",tag:[TAG_ELECTRODE_ALL,TAG_SHIRT]},
	{tip:"将套有衫环的托座放入压环内",tag:[TAG_ELECTRODE_ALL,TAG_BRACKET],action:ACTION_DO2},
	{tip:"用工具插入托座底部槽内顺时针旋紧",tag:[TAG_ELECTRODE_ALL,TAG_PRESSURE],action:ACTION_DO3},
	{tip:"将组装好的膜架嵌入紧帽中",tag:[TAG_ELECTRODE_ALL,TAG_PRESSURE],action:ACTION_DO4},
	{tip:"从物品库中取出装有蒸馏水瓶",tag:[TAG_LIB,TAG_LIB_KETTLE]},   
	{tip:"将蒸馏水倒入电极腔体至溢出黄金表面",tag:TAG_KETTLE},
	{tip:"将黄金电极中的蒸馏水倒出",tag:[TAG_ELECTRODE_ALL,TAG_LEFT_1],action:ACTION_DO1},
	{tip:"从物品库中取出装有溶氧电极溶液的试剂瓶",tag:[TAG_LIB,TAG_LIB_BOTTLE]},
	{tip:"打开试剂瓶",tag:[TAG_BOTTLE_ALL,TAG_LID]},
	{tip:"将试剂瓶中溶解氧电极溶液倒入电极腔体至溢出黄金表面,要求黄金电极向上且垂直倒置",tag:[TAG_BOTTLE_ALL,TAG_BOTTLE]},
	{tip:"将紧帽旋入黄金电极头部,旋入过程中薄膜逐渐贴紧黄金电极表面至平整",tag:[TAG_ELECTRODE_ALL,TAG_TIGHT],action:ACTION_DO2},
	{tip:"将溶解氧电极插入溶解氧仪的相应插孔",tag:[TAG_ELECTRODE_ALL,TAG_LEFT_1],action:ACTION_DO2},
	{tip:"打开溶解氧仪,将溶解氧仪开关拨动到调零位置",tag:[TAG_MP_INSTRUMENT,TAG_MAIN,TAG_BUTTON],action:ACTION_DO1},
	{tip:"转动仪器右侧调零旋钮,将仪器显示数值调整到00.0",tag:[TAG_MP_INSTRUMENT,TAG_MAIN,TAG_BUTTON1]},
	{tip:"将溶解氧仪开关拨到测试位置",tag:[TAG_MP_INSTRUMENT,TAG_MAIN,TAG_BUTTON],action:ACTION_DO2},
	{tip:"从物品库中取出装有西湖中提取的水的水样瓶",tag:[TAG_LIB,TAG_LIB_BOTTLE1]},
	{tip:"从物品库中取出烧杯",tag:[TAG_LIB,TAG_LIB_BEAKER]},
	{tip:"打开水样瓶瓶盖",tag:[TAG_BOTTLE_ALL,TAG_LID]},
	{tip:"将水样瓶中水样倒入烧杯中",tag:[TAG_BOTTLE_ALL,TAG_BOTTLE1]},
	{tip:"将溶解氧电极浸入烧杯中,等待一段时间,待数值稳定时,记录数值",tag:[TAG_ELECTRODE_ALL,TAG_LEFT_1],action:ACTION_DO3},
	{tip:"关闭溶解氧仪",tag:[TAG_MP_INSTRUMENT,TAG_MAIN,TAG_BUTTON],action:ACTION_DO3},
	{tip:"恭喜过关",over:true}
];
over = {tip:"恭喜过关"};



